import request from 'umi-request';

export async function getOvertimePage(params) {
  return request('/api/member/api-member/employeeOverwork/listEmployeeOverWork', {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      ...params
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getRecordList(params) {
  return request('/api/member/api-member/employeeOverwork/listRecordOverWork', {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
      ...params
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getSporadicList(params) {
  return request('/api/member/api-member/employeeOverworkOdd/listOddMember', {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.records,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function getShiftList(params) {
  return request('/api/member/api-member/memberLeave/getShiftPage', {
    method: 'get',
    params:{
      pageNum: params.current,
      pageSize: params.pageSize,
    },
  }).then((res) => {
    if (res.flag) {
      const data = res.data;
      return {
        current: data.currPage,
        data: data.list,
        pageSize: data.pageSize,
        success: true,
        total: data.totalCount,
      };
    } else {
      return {};
    }
  });
}

export async function saveAndUpdateShiftInfo(params) {
  return request('/api/member/api-member/memberLeave/saveAndUpdateShiftInfo', {
    method: 'POST',
    data: {
      ...params
    },
  }).then((res) => {
    return res;
  });
}

export async function deleteShift(id) {
  return request(`/api/member/api-member/memberLeave/deleteShift`, {
    method: 'delete',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function shiftBpm(id) {
  return request('/api/member/api-member/bpm/memberShiftBpm', {
    method: 'get',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function getFrequencyList() {
  return request('/api/member/api-member/memberLeave/getFrequencyList', {
    method: 'get',
  }).then((res) => {
    return res.data;
  });
}

export async function getShiftFrequency(params) {
  return request('/api/member/api-member/memberLeave/getShiftFrequency', {
    method: 'get',
    params: {...params}
  }).then((res) => {
    return res.data;
  });
}

export async function saveOverWork(params) {
  return request('/api/member/api-member/employeeOverwork/saveOverWork', {
    method: 'POST',
    data: {
      ...params,
    },
  }).then((res) => {
    return res;
  });
}

export async function deleteOverWorkById(id) {
  return request(`/api/member/api-member/employeeOverwork/deleteOverWorkById`, {
    method: 'delete',
    params: {
      id: id
    }
  }).then((res) => {
    return res;
  });
}

export async function overWorkBpm(id) {
  return request('/api/member/api-member/bpm/overWorkBpm', {
    method: 'POST',
    data: {
      id:id
    },
    requestType: 'form'
  }).then((res) => {
    return res;
  });
}
